package LessonWork;

import javax.xml.stream.Location;
import java.util.Arrays;
import java.util.Scanner;

public class Josephs {
    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);

        //获取人数数量
        int total = scanner.nextInt();
        //获取开始的位置
        int start = scanner.nextInt();
        //获取每个distance个人
        int distance = scanner.nextInt();

        Integer[] jos = new Integer[total];

        //实现初步赋值
        for (int i=0;i< jos.length;i++){
            jos[i]=i+1;
        }

        SinglyList<Integer> jose = new SinglyList<>(jos);

        //首尾相连
        jose.getLocation(jose.size+1).next = jose.getLocation(2);

        //从 start 位置开始循环
        Node<Integer> location = jose.getLocation(start+1);

        while (location.next!=location){
            for (int i=1;i<distance-1;i++){
                location=location.next;
            }
            System.out.println(location.next.data);
            location.next=location.next.next;
            location=location.next;
        }
        System.out.println("最后存活下来的人是"+location.data);
    }
}
